//
//  ViewController.m
//  cookeis
//
//  Created by ming on 16/10/15.
//  Copyright © 2016年 ming. All rights reserved.
//

#import "ViewController.h"

@interface ViewController ()<UIWebViewDelegate>
@property (weak, nonatomic) IBOutlet UIWebView *webView;

@end

@implementation ViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    [self.webView loadRequest:[NSURLRequest requestWithURL:[NSURL URLWithString:@"https://api.weibo.com/oauth2/authorize?response_type=code&client_id=590390308&forcelogin=true&redirect_uri=http%3A%2F%2F52it.me%2F%3Fconnect%3Dsina%26action%3Dcallback"]]];
    //[self.webView loadRequest:[NSURLRequest requestWithURL:[NSURL URLWithString:@"http://52it.me/wp-admin"]]];

//
  
    
    self.webView.delegate = self;

}

-(BOOL)webView:(UIWebView *)webView shouldStartLoadWithRequest:(NSURLRequest *)request navigationType:(UIWebViewNavigationType)navigationType{
    if ([request.URL.absoluteString hasPrefix:@"http://52it.me/"]) {
         NSLog(@"%@",request.URL.absoluteString);
        NSUserDefaults *dfaults = [NSUserDefaults standardUserDefaults];
        NSArray *allCookies = [[NSHTTPCookieStorage sharedHTTPCookieStorage] cookies];
        for (NSHTTPCookie *cookies in allCookies) {

            if ( [cookies.name isEqual: @"wordpress_logged_in_f4f3805fe0de488e866132af9df94f21"]){
                
                NSLog(@"%@",cookies.value);
            }
            
        }

    }
   
    return YES;
}

- (void)webViewDidFinishLoad:(UIWebView *)webView{
    
    
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

@end
